//
// Created by jwhww on 25-9-21.
//

#include "AllHeadFile.h"

//------------------------------------------------------------------------------------------------------
// 函数简介		   can过滤器
// 使用示例         bsp_can_filter_init(&hcan1);
// 参数介绍         *hcan                   输入你用的哪个can，对于c板来说是&hcan1 或 &hcan2
// 返回参数
// 备注信息         内部调用
//------------------------------------------------------------------------------------------------------
static void bsp_can_filter_init(CAN_HandleTypeDef *hcan)
{
    CAN_FilterTypeDef can_filter_st;
    can_filter_st.FilterActivation = ENABLE;
    can_filter_st.FilterMode = CAN_FILTERMODE_IDMASK;
    can_filter_st.FilterScale = CAN_FILTERSCALE_32BIT;
    can_filter_st.FilterIdHigh = 0x0000;
    can_filter_st.FilterIdLow = 0x0000;
    can_filter_st.FilterMaskIdHigh = 0x0000;
    can_filter_st.FilterMaskIdLow = 0x0000;
    can_filter_st.FilterBank = 0;
    can_filter_st.FilterFIFOAssignment = CAN_FILTER_FIFO0;
    can_filter_st.SlaveStartFilterBank = 14;

    HAL_CAN_ConfigFilter(hcan, &can_filter_st);
}

//------------------------------------------------------------------------------------------------------
// 函数简介		  can初始化
// 使用示例         bsp_can_init(&hcan1);
// 参数介绍         *hcan                   输入你用的哪个can，对于c板来说是&hcan1 或 &hcan2
// 返回参数
// 备注信息         想用啥自己加
//------------------------------------------------------------------------------------------------------
void bsp_can_init(void) {
    //can1
    bsp_can_filter_init(&hcan1);
    HAL_CAN_ActivateNotification(&hcan1, CAN_IT_RX_FIFO0_MSG_PENDING);  //FIFO0
    HAL_CAN_Start(&hcan1);
    //can2
    bsp_can_filter_init(&hcan2);
    HAL_CAN_ActivateNotification(&hcan2, CAN_IT_RX_FIFO1_MSG_PENDING);  //FIFO1
    HAL_CAN_Start(&hcan2);
}

